import request from '@/utils/request'

/**
 * 发送短信验证码
 * @param {string} phone - 手机号
 * @returns {Promise}
 */
export function sendSmsCode(phone) {
  return request({
    url: '/auth/sms-code',
    method: 'post',
    data: { phone },
  })
}

/**
 * 手机号+验证码登录
 * @param {string} phone - 手机号
 * @param {string} code - 验证码
 * @returns {Promise}
 */
export function loginByPhone(phone, code) {
  return request({
    url: '/auth/login-phone',
    method: 'post',
    data: { phone, code },
  })
}

/**
 * 微信登录
 * @param {string} code - 微信授权码
 * @returns {Promise}
 */
export function loginByWechat(code) {
  return request({
    url: '/auth/login-wechat',
    method: 'post',
    data: { code },
  })
}

/**
 * 退出登录
 * @returns {Promise}
 */
export function logout() {
  return request({
    url: '/auth/logout',
    method: 'post',
  })
}

/**
 * 获取用户信息
 * @returns {Promise}
 */
export function getUserInfo() {
  return request({
    url: '/user/info',
    method: 'get',
  })
}
